digipot10 2.2.0
Loading...
Searching...
No Matches
digipot10.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef DIGIPOT10_H
29#define DIGIPOT10_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
60
65
70
75#define DIGIPOT10_REG_VOLATILE_WIPER_0 0x01
76#define DIGIPOT10_REG_VOLATILE_WIPER_1 0x02
77#define DIGIPOT10_REG_NV_WIPER_0 0x03
78#define DIGIPOT10_REG_NV_WIPER_1 0x04
79#define DIGIPOT10_REG_GP_DATA_0 0x05
80#define DIGIPOT10_REG_GP_DATA_1 0x06
81#define DIGIPOT10_REG_GP_DATA_2 0x07
82#define DIGIPOT10_REG_STATUS 0x08
83#define DIGIPOT10_REG_LOCK 0x09
84#define DIGIPOT10_REG_TERMINAL_CONTROL 0x0A
85#define DIGIPOT10_REG_SYNC 0x0B
86#define DIGIPOT10_REG_CRC 0x0C
87#define DIGIPOT10_REG_RESET 0x0D
88#define DIGIPOT10_REG_NV_W_0_COUNT 0x15
89#define DIGIPOT10_REG_NV_W_1_COUNT 0x17
90#define DIGIPOT10_REG_DATA_0_COUNT 0x19
91#define DIGIPOT10_REG_DATA_1_COUNT 0x1B
92#define DIGIPOT10_REG_DATA_2_COUNT 0x1D
93
98#define DIGIPOT10_CMD_REG_MASK 0xF8
99#define DIGIPOT10_CMD_OP_WRITE_DATA 0x00
100#define DIGIPOT10_CMD_OP_READ_DATA 0x07
101#define DIGIPOT10_CMD_OP_INCREMENT_WIPER 0x02
102#define DIGIPOT10_CMD_OP_DECREMENT_WIPER 0x04
103#define DIGIPOT10_CMD_OP_MASK 0x07
104#define DIGIPOT10_DATA_MASK 0x03FF
105 // digipot10_reg
107
112
117
122#define DIGIPOT10_STATUS_ECED 0x0040
123#define DIGIPOT10_STATUS_SPIWDT 0x0020
124#define DIGIPOT10_STATUS_CMDERR 0x0010
125#define DIGIPOT10_STATUS_CRCERR 0x0008
126#define DIGIPOT10_STATUS_SRST 0x0004
127#define DIGIPOT10_STATUS_POR 0x0002
128#define DIGIPOT10_STATUS_MTPMA 0x0001
129
134#define DIGIPOT10_LOCK_LOCKNV 0x0002
135#define DIGIPOT10_LOCK_LOCKV 0x0001
136
141#define DIGIPOT10_TCON0_R1A 0x0020
142#define DIGIPOT10_TCON0_R1W 0x0010
143#define DIGIPOT10_TCON0_R1B 0x0008
144#define DIGIPOT10_TCON0_R0A 0x0004
145#define DIGIPOT10_TCON0_R0W 0x0002
146#define DIGIPOT10_TCON0_R0B 0x0001
147
152#define DIGIPOT10_SYNC_WLAT 0x0004
153#define DIGIPOT10_SYNC_WRSYNC 0x0002
154#define DIGIPOT10_SYNC_IDSYNC 0x0001
155
160#define DIGIPOT10_CRC_CRCEN 0x0001
161
166#define DIGIPOT10_RESET_SWRSTVAL 0x00A5
167
172#define DIGIPOT10_WIPER_FULL_SCALE 0x03FF
173#define DIGIPOT10_WIPER_MID_SCALE 0x0200
174#define DIGIPOT10_WIPER_ZERO_SCALE 0x0000
175
181#define DIGIPOT10_DEVICE_ADDRESS_A1A0_00 0x2C
182#define DIGIPOT10_DEVICE_ADDRESS_A1A0_01 0x2D
183#define DIGIPOT10_DEVICE_ADDRESS_A1A0_10 0x2E
184#define DIGIPOT10_DEVICE_ADDRESS_A1A0_11 0x2F
185
194#define DIGIPOT10_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
195#define DIGIPOT10_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
196 // digipot10_set
198
203
208
213#define DIGIPOT10_MAP_MIKROBUS( cfg, mikrobus ) \
214 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
215 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
216 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
217 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
218 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
219 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
220 // digipot10_map // digipot10
223
234
239struct digipot10_s;
240typedef err_t ( *digipot10_master_io_t )( struct digipot10_s*, uint8_t, uint8_t*, uint8_t );
241
259
264typedef struct
265{
266 pin_name_t scl;
267 pin_name_t sda;
268 pin_name_t miso;
269 pin_name_t mosi;
270 pin_name_t sck;
271 pin_name_t cs;
272
273 uint32_t i2c_speed;
274 uint8_t i2c_address;
275
276 uint32_t spi_speed;
277 spi_master_mode_t spi_mode;
278 spi_master_chip_select_polarity_t cs_polarity;
279
281
283
294
300
311
327
342
356
369err_t digipot10_write_reg ( digipot10_t *ctx, uint8_t reg, uint16_t data_in );
370
383err_t digipot10_read_reg ( digipot10_t *ctx, uint8_t reg, uint16_t *data_out );
384
396err_t digipot10_increment_wiper ( digipot10_t *ctx, uint8_t reg );
397
409err_t digipot10_decrement_wiper ( digipot10_t *ctx, uint8_t reg );
410
422
434err_t digipot10_set_wiper_0 ( digipot10_t *ctx, uint16_t wiper );
435
447err_t digipot10_set_wiper_1 ( digipot10_t *ctx, uint16_t wiper );
448
449#ifdef __cplusplus
450}
451#endif
452#endif // DIGIPOT10_H
453 // digipot10
455
456// ------------------------------------------------------------------------ END
err_t(* digipot10_master_io_t)(struct digipot10_s *, uint8_t, uint8_t *, uint8_t)
Definition digipot10.h:240
digipot10_return_value_t
DIGI POT 10 Click return value data.
Definition digipot10.h:289
@ DIGIPOT10_OK
Definition digipot10.h:290
@ DIGIPOT10_ERROR
Definition digipot10.h:291
digipot10_drv_t
DIGI POT 10 Click driver selector.
Definition digipot10.h:229
@ DIGIPOT10_DRV_SEL_SPI
Definition digipot10.h:230
@ DIGIPOT10_DRV_SEL_I2C
Definition digipot10.h:231
struct digipot10_s digipot10_t
DIGI POT 10 Click context object.
void digipot10_drv_interface_sel(digipot10_cfg_t *cfg, digipot10_drv_t drv_sel)
DIGI POT 10 driver interface setup function.
err_t digipot10_set_wiper_0(digipot10_t *ctx, uint16_t wiper)
DIGI POT 10 set wiper 0 function.
err_t digipot10_read_reg(digipot10_t *ctx, uint8_t reg, uint16_t *data_out)
DIGI POT 10 read register function.
err_t digipot10_set_wiper_1(digipot10_t *ctx, uint16_t wiper)
DIGI POT 10 set wiper 1 function.
err_t digipot10_decrement_wiper(digipot10_t *ctx, uint8_t reg)
DIGI POT 10 decrement wiper function.
err_t digipot10_write_reg(digipot10_t *ctx, uint8_t reg, uint16_t data_in)
DIGI POT 10 write register function.
err_t digipot10_init(digipot10_t *ctx, digipot10_cfg_t *cfg)
DIGI POT 10 initialization function.
err_t digipot10_soft_reset(digipot10_t *ctx)
DIGI POT 10 software reset function.
err_t digipot10_default_cfg(digipot10_t *ctx)
DIGI POT 10 default configuration function.
void digipot10_cfg_setup(digipot10_cfg_t *cfg)
DIGI POT 10 configuration object setup function.
err_t digipot10_increment_wiper(digipot10_t *ctx, uint8_t reg)
DIGI POT 10 increment wiper function.
This file contains SPI specific macros, functions, etc.
DIGI POT 10 Click configuration object.
Definition digipot10.h:265
digipot10_drv_t drv_sel
Definition digipot10.h:280
uint32_t i2c_speed
Definition digipot10.h:273
spi_master_chip_select_polarity_t cs_polarity
Definition digipot10.h:278
pin_name_t sck
Definition digipot10.h:270
spi_master_mode_t spi_mode
Definition digipot10.h:277
pin_name_t mosi
Definition digipot10.h:269
uint32_t spi_speed
Definition digipot10.h:276
pin_name_t scl
Definition digipot10.h:266
pin_name_t miso
Definition digipot10.h:268
pin_name_t sda
Definition digipot10.h:267
pin_name_t cs
Definition digipot10.h:271
uint8_t i2c_address
Definition digipot10.h:274
DIGI POT 10 Click context object.
Definition digipot10.h:247
spi_master_t spi
Definition digipot10.h:249
digipot10_drv_t drv_sel
Definition digipot10.h:253
digipot10_master_io_t read_f
Definition digipot10.h:256
i2c_master_t i2c
Definition digipot10.h:248
digipot10_master_io_t write_f
Definition digipot10.h:255
uint8_t slave_address
Definition digipot10.h:251
pin_name_t chip_select
Definition digipot10.h:252